home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / IFolderMatrix.m < prev    next >
Text File  |  1993-01-12  |  7KB  |  271 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "IFolderMatrix.h"
  5. #import "TransparentWindow.h"
  6. #import "IDataGroupBrowser.h"
  7. #import "INXBrowserCellWithLinkedObject.h"
  8. #import "IUifNode.h"
  9. #import "InfoD.h"
  10. #import "ITreeNodeD.h"
  11. #import "AcceptWindow.h"
  12. #import "INntpIO.h"
  13. #import "ITreeBrowser.h"
  14. #import "errdebug.h"
  15. #import "data_types.h"
  16.  
  17. #import <appkit/NXImage.h>
  18. #import <appkit/Application.h>
  19. #import <appkit/ClipView.h>
  20. #import <appkit/ButtonCell.h>
  21. #import <appkit/Font.h>
  22. #import <string.h>
  23.  
  24. @implementation IFolderMatrix
  25.  
  26. - initFrame:(NXRect *)frameRect
  27. {
  28.     [super initFrame:frameRect];
  29.     isPalette = YES;
  30.     //default TransparentWindow class
  31.     iTransparentWindowClass = [TransparentWindow class];
  32.     
  33.     return self;
  34. }
  35.  
  36. - (BOOL)acceptsFirstMouse
  37. {
  38.     return (YES);
  39. }
  40.  
  41. - selectNewsgroupInBrowser:sender
  42. {
  43.     const char     *newsgroupName;
  44.     char    strTmp[256];
  45.     
  46.     newsgroupName = [selectedCell title];
  47.     DBG(1,fprintf(stderr,"-- selectCellInBrowser newsgroup = %s\n", 
  48.                                 newsgroupName));
  49.     if ([self selectedCell] == [cellList objectAt:0]) {
  50.     // nextStation icon was clicked, initialize newsgroup browser
  51.     //    set root list node first, 
  52.     //    and load cells into column 0
  53.     [oNewsgroupBrowser setRootListnode:
  54.             [[oNewsgroupBrowser iOmodule] subDirectoryOf:nil]];
  55.     [oNewsgroupBrowser loadColumnZero];
  56.     return (self);
  57.     } else {
  58.     // other newsgroup icon(closedFolder icon) was clicked.
  59.     if ([[oNewsgroupBrowser iOmodule] newsGroupMode] == Tree) {
  60.         // mode of newsgroup browser is tree
  61.         [oNewsgroupBrowser setPathSeparator:'.'];
  62.         strTmp[0] = '.'; strTmp[1] = '\0';
  63.         strncat (strTmp, newsgroupName, sizeof(strTmp)-2);
  64.         [oNewsgroupBrowser setPath:strTmp];
  65.     } else {
  66.         // mode is flat
  67.         [oNewsgroupBrowser setPathSeparator:'/'];
  68.         strTmp[0] = '/'; strTmp[1] = '\0';
  69.         strncat (strTmp, newsgroupName, sizeof(strTmp)-2);
  70.         [oNewsgroupBrowser setPath:strTmp];
  71.     }
  72.     // click selected cell
  73.     [[oNewsgroupBrowser 
  74.         matrixInColumn:[oNewsgroupBrowser selectedColumn]] sendAction];
  75.     return (self);
  76.     }
  77. }
  78.  
  79. - setRootName:(char *)rootName
  80. {
  81.     id        rootCell;
  82.     
  83.     // copy root name
  84.     strncpy (iRootName, rootName, (sizeof(iRootName)-1));
  85.     // make root cell
  86.     [self addCol];
  87.     rootCell = [self cellAt:0 :0];
  88.     [rootCell setIcon:NEXTSTATION];
  89.     [rootCell setTitle:iRootName];
  90. //    [self sizeToCells];
  91.     return (rootCell);
  92. }
  93.  
  94. - mouseDown:(NXEvent *)theEvent
  95. {
  96.     register BOOL    inside;
  97.     int        shouldLoop = YES;
  98.     int     oldMask;
  99.     NXEvent    *nextEvent;
  100.     NXPoint    hitPoint;
  101.     int        hitRow, hitCol;
  102.     id        hitCell;
  103.     NXRect    cellIconRect;
  104.     NXRect    iconWindowRect;
  105.     id        image, iconWindow;
  106.     NXPoint    offset, mouseLocation;
  107.     
  108.     hitPoint = theEvent->location;
  109.     [self convertPoint:&hitPoint fromView:nil];
  110.     [self getRow:&hitRow andCol:&hitCol forPoint:&hitPoint];
  111.     hitCell = [self cellAt:hitRow :hitCol];
  112.     // cell frame sould be passed to get icon rect for its cell
  113.     [self getCellFrame:&cellIconRect at:hitRow :hitCol];
  114.     [hitCell getIconRect:&cellIconRect];
  115.     DBG(1,fprintf(stderr," cellIconRect.origin.x = %f\t y = %f\n"
  116.                  " cellIconRect.size.width = %f\t height = %f\n",
  117.              cellIconRect.origin.x, cellIconRect.origin.y,
  118.              cellIconRect.size.width, cellIconRect.size.height));
  119.  
  120.     if (!NXPointInRect(&hitPoint, &cellIconRect) || 
  121.                     strcmp([hitCell title], "") == 0) {
  122.     // if hit point is not in icon or cell does not have title(=blank
  123.     // cell) or hitCell is nextStation icon, return
  124.     DBG(1,fprintf(stderr,"-- not in icon rect or blank cell\n"));
  125.     return (self);
  126.     }
  127.     
  128.     oldMask = [window addToEventMask:NX_LMOUSEDRAGGEDMASK];
  129.     while (shouldLoop) {
  130.     nextEvent = [NXApp getNextEvent:
  131.                     (NX_LMOUSEUPMASK | NX_LMOUSEDRAGGEDMASK)];
  132.     hitPoint = nextEvent->location;
  133.     [self convertPoint:&hitPoint fromView:nil];
  134.     inside = NXPointInRect(&hitPoint, &cellIconRect);
  135.     switch (nextEvent->type) {
  136.     case NX_LMOUSEUP:
  137.         shouldLoop = NO;
  138.         if (inside) {
  139.         // click cell,  send action to the target
  140.         //[super mouseDown:nextEvent];
  141.         [self selectCell:hitCell];
  142.         [self sendAction];
  143.         }
  144.         break;
  145.     case NX_LMOUSEDRAGGED:
  146.         if ([hitCell image] == [NXImage findImageNamed:NEXTSTATION]) {
  147.         // can not drag nextStation icon(because it root)
  148.         break;
  149.         }
  150.         if (inside) {
  151.         // create icon window and drag it
  152.         iconWindowRect = cellIconRect;
  153.  
  154.         // convert icon rect(cellIconRect) to global coord.
  155.         [window convertBaseToScreen:&(iconWindowRect.origin)];
  156.  
  157.         // hitCell is an obj. from ButtonCell, its image will be 
  158.         // used for icon window image
  159.         image = [hitCell image];
  160.         iconWindow = [[iTransparentWindowClass
  161.                     allocFromZone:[self zone]] 
  162.                         initForImage:image 
  163.                     at:&(iconWindowRect.origin) 
  164.                     forView:hitCell];
  165.  
  166.         // compute the offset from the image's origin to 
  167.         // the mouse location
  168.         offset.x = hitPoint.x - cellIconRect.origin.x;
  169.         offset.y = (cellIconRect.origin.y + cellIconRect.size.height)
  170.                              - hitPoint.y;
  171.         
  172.         // convert mouse down location to screen coord.
  173.         mouseLocation = nextEvent->location;
  174.         [window convertBaseToScreen:&mouseLocation];
  175.         
  176.         // if this FolderMatrix is not palette matrix, remove 
  177.         // my icon image and clear title
  178.         if ([self isPalette] == NO) {
  179.             [hitCell setImage:[NXImage findImageNamed:BLANKICON]];
  180.             [hitCell setTitle:""];
  181.         }
  182.         // go into dragging loop in TranseparentWindow
  183.         [iconWindow dragFromMouseDown:&mouseLocation
  184.                          mouseOffset:&offset];
  185.         // iconWindow is freed automatically when dropped
  186.         }
  187.         break;
  188.     default:
  189.         break;
  190.     }
  191.     }
  192.     [window setEventMask:oldMask];
  193.     return (self);
  194. }
  195.  
  196. - registerCellAt:(int)krow :(int)kcol window:kwindow
  197. {
  198.     NXRect    rect;
  199.     id        kcell;
  200.     id        awindow;
  201.  
  202.     // if kwindow == nil, use window under view of IFolderMatrix
  203.     if (kwindow == nil) {
  204.     awindow = [self window];
  205.     } else {
  206.     awindow = kwindow;
  207.     }
  208.     if ([awindow respondsTo:@selector(registerRect:forCell:controlView:)]) {
  209.     [self getCellFrame:&rect at:krow :kcol];
  210.     [self convertRect:&rect toView:nil];
  211.     
  212.     kcell = [self cellAt:krow :kcol];
  213.     return ([awindow registerRect:&rect forCell:kcell controlView:self]);
  214.     }
  215.     return nil;
  216. }
  217.     
  218. - unregisterCellAt:(int)krow :(int)kcol window:kwindow
  219. {
  220.     id        kcell;
  221.     id        awindow;
  222.  
  223.     // if kwindow == nil, use window under view of IFolderMatrix
  224.     if (kwindow == nil) {
  225.     awindow = [self window];
  226.     } else {
  227.     awindow = kwindow;
  228.     }
  229.     
  230.     if ([awindow respondsTo:@selector(registerRect:forCell:controlView:)]) {
  231.     kcell = [self cellAt:krow :kcol];
  232.     return ([awindow unregisterRectForCell:kcell]);
  233.     } else {
  234.     return nil;
  235.     }
  236. }
  237.  
  238. - registerCells
  239. {
  240.     int        trow, tcol;
  241.  
  242.     // if our new window's an AcceptWindow, we'll "register" cell frame with it
  243.     if ([window respondsTo:@selector(registerRect:forCell:controlView:)]) {
  244.     tcol = numCols; trow = numRows;
  245.     while(trow--) {
  246.         while(tcol--) {
  247.         [self registerCellAt:trow :tcol window:window];
  248.         }
  249.         tcol = numCols;
  250.     }
  251.     }
  252.     return self;
  253. }
  254.  
  255. - sizeTo:(float)width :(float)height
  256. {
  257.     DBG(10,fprintf(stderr," martix sizeTo::++++++++"));
  258.     // every time the matrix's frame is resized, we will register cell's 
  259.     // frame to AcceptWindow.
  260.     [self registerCells];
  261.  
  262.     return ([super sizeTo:width :height]);
  263. }
  264.  
  265. - (BOOL)isPalette
  266. {
  267.     return isPalette;
  268. }
  269.  
  270. @end
  271.